<%@ page import="com.zhiyou100.entityclass.Student" %><%--
  Created by IntelliJ IDEA.
  User: yang
  Date: 7/21/20
  Time: 17:20
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>EL 表达式 11大内置对象</title>
</head>
<body>
<%
    pageContext.setAttribute("aa", "aa_value_page");
    pageContext.setAttribute("stu", new Student(1l, "杨磊", "男", 20l, 1l));
    request.setAttribute("aa", "aa_value_request");
    session.setAttribute("aa", "aa_value_session");
    application.setAttribute("aa", "aa_value_application");
%>

<h1>内置对象1-1 域对象 pageScope</h1>
<p>pageScope.aa=${pageScope.get("aa")}</p>
<p>aa=${aa}</p>
<p>pageScope.student.sname=${pageScope.get("stu").sname}</p>

<h1>内置对象1-2 域对象 request</h1>
<p>request.aa=${requestScope.get("aa")}</p>


<h1>内置对象1-3 域对象 sessionScope</h1>
<p>sessionScope.aa=${sessionScope.get("aa")}</p>


<h1>内置对象1-4 域对象 applicationScope</h1>
<p>applicationScope.aa=${applicationScope.get("aa")}</p>


<h1>内置对象2-1 请求参数 param </h1>
<%-- http://localhost:8082/test/el/el2.jsp?name=%E6%9D%A8%E7%A3%8A&enjoy=1&enjoy=2&enjoy=3 --%>
<p>name=${param.get("name")}</p>
<p>
    enjoy[0]=${paramValues.get("enjoy")[0]}
    enjoy[1]=${paramValues.get("enjoy")[1]}
    enjoy[2]=${paramValues.get("enjoy")[2]}
</p>


<h1>内置对象 7，8，9 header headerValues cookie</h1>

<p>User-Agent: ${header.get("User-Agent")}</p>
<p>Host: ${header.get("Host")}</p>


<%-- headerValues 还是获取所有值, 没有重复的请求头 所以 [0]下表 就是其本身 --%>
<p>headerValues.Accept[0] ${headerValues["Accept"][0]}</p>
<p>accept-language[0] ${headerValues["accept-language"][0]}</p>
<p>Cookie[0] ${headerValues["Cookie"][0]}</p>



<%-- ${cookie} 获取的是所有 Cookie 组成的 集合 --%>
<p>Cookies ${cookie}</p>
<%-- ${cookie.get("c1")} 获取的是名字为 c1 的 Cookie 对象--%>
<p>Cookie c1 : ${cookie.get("c1")}</p>
<p>Cookie c1 name: ${cookie.get("c1").name}</p>
<p>Cookie c1 value: ${cookie.get("c1").value}</p>
<p>Cookie c2 name: ${cookie.get("c2").name}</p>
<p>Cookie c2 value: ${cookie.get("c2").value}</p>


<h1>内置对象 10 获取项目的初始化参数 initParam</h1>
<p>公司名字 ${initParam.get("companyName")}</p>
<p>公司名字
    <%=request.getServletContext().getInitParameter("companyName")%>
</p>


<h1>内置对象 11 获取 pageContext 对象 </h1>
<%-- pageContext 作为域对象、全域查找、代理其他域、获取其他8个域 --%>
<p>项目路径 <%=request.getContextPath()%>
</p>
<p>项目路径 ${pageContext.request.contextPath}</p>


</body>
</html>
